
package com.android.formula.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.formula.R;
import com.android.formula.model.TypeSubSubject;
import com.android.formula.utils.CommonUtils;
import com.android.formula.utils.Constants;

public class TypeSubSubjectListAdapter extends TBaseAdapter<TypeSubSubject> {

    public TypeSubSubjectListAdapter(Context context, List<TypeSubSubject> items) {
        super(context, items);
    }

    @Override
    protected View getView(View convertView) {
        convertView = mInflater.inflate(R.layout.item_gridview, null, false);
        ViewHolder viewHolder = new ViewHolder(); // new ViewHolder
        viewHolder.init(convertView); // init views in ViewHolder
        convertView.setTag(viewHolder);
        return convertView;
    }

    @Override
    public void freeMemoryView(View v) {
    }

    @Override
    protected void setViews(View view, TypeSubSubject item) {
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        viewHolder.titleTv.setText(item.getSsSubjectName());
        CommonUtils.setImageFromDrawable(mContext,
                Constants.IMAGE_TYPE_SUB_SUB_SUBJECT + item.getSsSubjectId(), viewHolder.itemImageIv);
    }

    protected class ViewHolder {
        public TextView titleTv;

        public ImageView itemImageIv;

        public void init(View convertView) {
            itemImageIv = (ImageView) convertView.findViewById(R.id.item_gridview_img);
            titleTv = (TextView) convertView.findViewById(R.id.item_gridview_txt);
        }
    }
}
